package 力扣日常刷题.木22二月.第11天217;

/**
 * @author 帅小伙
 * @date 2022/2/17
 * @description
 */
public class Demo86移动零 {

    public static void main(String[] args) {
        moveZeroes(new int[]{0,1,0,3,12});
    }

    public static void moveZeroes(int[] nums) {
        int n = nums.length,l = 0,r = 0;
        while (r < n){
            if (nums[r] != 0) {
                swap(nums,l,r);
                l++;
            }
            r++;
        }
    }

    public static void swap(int[] nums,int l,int r) {
        int t = nums[l];
        nums[l] = nums[r];
        nums[r] = t;
    }

}
